package com.example.config;

import com.example.repository.HibernateStudentRepository;
import com.example.repository.impl.HibernateStudentRepositoryImpl;
import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
// 使用注解 @EnableTransactionManagement 开启事务支持
// @EnableTransactionManagement的作用和<tx:annotation-driven/>作用一样
// 这个注解的基于proxy模式解析类是org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration
// 基于aspectj模式的解析类是org.springframework.transaction.aspectj.AspectJTransactionManagementConfiguration
@EnableTransactionManagement
@Import(TransactionConfig.class)
//@EnableAspectJAutoProxy // 启用AspectJ自动代理
public class AppConfig {

    @Bean
    public HibernateStudentRepository hibernateStudentRepository(SessionFactory sessionFactory){
        return new HibernateStudentRepositoryImpl(sessionFactory);
    }
}
